home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / Newton Sample Code 1.1 / Views / Wrap It Up-2 / Wrap It Up.text < prev    next >
Encoding:
Text File  |  1994-02-28  |  4.2 KB  |  155 lines  |  [TEXT/MPS ]

  1. // Copyright © 1993-94 Apple Computer, Inc. All rights reserved.
  2.  
  3. constant kAppName := '|Wrapper:PIEDTS|;
  4.  
  5. // ---- End Project Data ----
  6.  
  7.  
  8. // ---- File Wrap It Up.t ----
  9. paragraphApp :=
  10.    {title: "Wrap It Up",
  11.     viewBounds: {top: 0, left: 0, right: 240, bottom: 336},
  12.     viewSetupFormScript:
  13.       func()
  14.       begin
  15.           constant kMaxWidth := 240;
  16.           constant kMaxHeight := 336;
  17.       
  18.           local b := GetAppParams();
  19.       
  20.           self.viewBounds := RelBounds(b.appAreaLeft, b.appAreaTop,
  21.                                                   Min(b.appAreaWidth, kMaxWidth),
  22.                                                   Min(b.appAreaHeight, kMaxHeight)
  23.                                               );
  24.       end,
  25.     _proto: protoApp,
  26.     debug: "paragraphApp"
  27.    };
  28.  
  29. _view000 := /* child of paragraphApp */
  30.    {viewFlags: 33,
  31.     viewFormat: 337,
  32.     viewBounds: {left: 9, top: 25, right: 231, bottom: 159},
  33.     viewclass: 77
  34.    };
  35.  
  36. theParagraph := /* child of _view000 */
  37.    {viewFlags: 6657,
  38.     viewFormat: 337,
  39.     viewFont: userFont12,
  40.     viewBounds: {left: 9, top: 9, right: 215, bottom: 71},
  41.     text: "Word",
  42.     viewJustify: 0,
  43.     viewclass: 81,
  44.     debug: "theParagraph"
  45.    };
  46. // View theParagraph is declared to paragraphApp
  47.  
  48. // After Script for "theParagraph"
  49. thisView := theParagraph;
  50. begin
  51.    thisView.viewFlags := BOR(thisView.viewFlags, vCalculateBounds);
  52.    // Set the vCalculateBounds flag here, because it's not in the
  53.    // viewFlags editor.
  54.  
  55.    thisView.viewLineSpacing := nil;
  56.    // Make sure this slot is set here so it doesn't inherit
  57.    // GetRoot() has a viewLineSpacing slot!
  58. end
  59.  
  60.  
  61.  
  62.  
  63.  
  64. addAbove := /* child of paragraphApp */
  65.    {text: "Add word above",
  66.     buttonClickScript:
  67.       func()
  68.       begin
  69.          SetValue(theParagraph, 'text, theParagraph.text && GetRandomWord(0, 20));
  70.          SetValue(theParagraph, 'viewBounds, theParagraph.viewBounds);
  71.       
  72.          // the second SetValue is needed to tweak the clParagraphView into
  73.          // updating an internal cache.  It's a workarond for a clParagraphView
  74.          // bug.  The SetValue doesn't necessarily have to be for viewBounds.
  75.       end,
  76.     viewBounds: {left: 10, top: 170, right: 110, bottom: 182},
  77.     _proto: protoTextButton,
  78.     debug: "addAbove"
  79.    };
  80.  
  81.  
  82.  
  83. addBelow := /* child of paragraphApp */
  84.    {text: "Add word below",
  85.     buttonClickScript:
  86.       func()
  87.       begin
  88.          SetValue(anotherParagraph, 'text, anotherParagraph.text && GetRandomWord(0, 20));
  89.       end,
  90.     viewBounds: {left: 130, top: 170, right: 230, bottom: 182},
  91.     _proto: protoTextButton,
  92.     debug: "addBelow"
  93.    };
  94.  
  95.  
  96.  
  97. anotherParagraph := /* child of paragraphApp */
  98.    {viewFlags: 6657,
  99.     viewFormat: 337,
  100.     viewFont: userFont12,
  101.     viewBounds: {left: 17, top: 193, right: 223, bottom: 209},
  102.     text: "Word",
  103.     viewJustify: 0,
  104.     AdjustHeight:
  105.       // This Function is based on Mike Engber's WrappedHeight utility
  106.       // which calculates the height of wrapped text.  It's probably
  107.       // better to just include that function in your application and
  108.       // call it from here, but I didn't.  See the README for details.
  109.       
  110.       func()
  111.       begin
  112.          local width := viewBounds.right - viewBounds.left;
  113.          local height := ComputeParagraphHeight(self,0,width);
  114.        
  115.          if height = 50 then begin
  116.             local fontHeight := FontHeight(viewFont);
  117.             local xNewLines  := ceiling(50/fontHeight);
  118.             local xPara := {
  119.                               viewFont: viewFont,
  120.                               text: NStringCat(Stringer(Array(xNewLines,$\n)), text),
  121.                             };
  122.             height := ComputeParagraphHeight(xPara,0,width) - xNewLines*fontHeight;
  123.          end;
  124.       
  125.          local newBounds := viewBounds;
  126.          newBounds.bottom := newBounds.top + height;
  127.          SetValue(self, 'viewBounds, newBounds);
  128.       end;,
  129.     viewChangedScript:
  130.       func(slot, view)
  131.       begin
  132.          if slot = 'text and view = self then
  133.             :AdjustHeight();
  134.       end,
  135.     viewclass: 81,
  136.     debug: "anotherParagraph"
  137.    };
  138. // View anotherParagraph is declared to paragraphApp
  139.  
  140. // After Script for "anotherParagraph"
  141. thisView := anotherParagraph;
  142. thisView.viewLineSpacing := nil;
  143.  
  144. // Make sure this slot is set here so it doesn't inherit
  145. // GetRoot() has a viewLineSpacing slot!
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153. // ---- Beginning of section for non used Layout files ----
  154.  
  155. // End of output